// 车辆相关
import { CarTypes, MainType, CarType } from '../types/car'
import request from '../utils/request'

// 新增车辆
export const CarPost = (carobj: CarTypes) => {
    return request.post('classes/car', carobj)
}

// 修改车辆信息
export const CarUpdate = (id: string, carobj: CarTypes) => {
    return request.put('classes/car/' + id, carobj)
}



// 获取车辆
interface SearchType {
    [key: string]: string | {}
}
export const CarGet = (page: number = 1, limit: number = 8, search = {} as SearchType) => {
    for (let i in search) {
        if (search[i] == '') {
            delete search[i];
        }
    }
    if (search.license) {
        search.license = { "$regex": `${search.license}`, "$options": "i" }

        console.log(search.license);
    }
    let skip = (page - 1) * limit
    return request.get('classes/car', {
        params: {
            limit,
            skip,
            count: 1,
            where: search
        }
    })
}

// 获取车牌号
export const licenseGet = () => {
    return request.get('classes/car')
}

// 获取维修类型
export const CateGet = () => {
    return request.get('classes/category')
}


// 新增维护记录
export const MainAdd = (obj: MainType) => {
    return request.post('classes/maintain', obj)
}
// 新增维护记录
export const MainDel = (id: string) => {
    return request.delete('classes/maintain/' + id)
}

// 获取维修记录
export const MainGet = (page: number = 1, limit: number = 8, search = {} as SearchType) => {
    for (let i in search) {
        if (search[i] == '') {
            delete search[i];
        }
    }
    let skip = (page - 1) * limit
    return request.get('classes/maintain', {
        params: {
            limit,
            skip,
            count: 1,
            where: search
        }
    })
}

// 获取校区
export const SchoolGet = () => {
    return request.get('classes/school')
}

// 新增准考车型
export const CarTypePost = (obj: CarType) => {
    return request.post('classes/cartype', obj)
}




// 准考车型
export const CarTypeGet = (page: number = 1, limit: number = 5, search = {} as SearchType) => {
    for (let i in search) {
        if (search[i] == '') {
            delete search[i];
        }
    }
    if (search.carType) {
        search.carType = { "$regex": `${search.carType}`, "$options": "i" }

    }
    let skip = (page - 1) * limit
    return request.get('classes/cartype', {
        params: {
            limit,
            skip,
            count: 1,
            where: search
        }
    })
}

